import React, { useState, useRef, useEffect } from 'react';
function Ref() {
	let [num, setNum] = useState(0);
	let refObj = useRef(num);

	useEffect(() => {
		console.log('组建更新', num);
		refObj.current = num;
	})

	return (
		<div>
			num: {num} <br />
			当前值: {refObj.current}
			<button onClick={() => {
				setNum(++num)
			}}>加</button>
			<button onClick={() => {
				alert(refObj.current);
			}}>试试</button>
		</div >
	)
}
export default Ref;

